package com.ftg.learn.springbootmq.topic.controller;

import com.ftg.learn.springbootmq.topic.entity.Order;
import com.ftg.learn.springbootmq.topic.entity.Product;
import com.ftg.learn.springbootmq.topic.entity.User;
import com.ftg.learn.springbootmq.topic.service.OrderService;
import com.ftg.learn.springbootmq.topic.service.ProductService;
import com.ftg.learn.springbootmq.topic.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/topic")
public class ECommerceController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private UserService userService;

    @Autowired
    private ProductService productService;

    // 订单相关接口
    @PostMapping("/order")
    public String createOrder(@RequestBody Order order) {
        orderService.createOrder(order);
        return "订单创建消息已发送";
    }

    @DeleteMapping("/order/{orderId}")
    public String cancelOrder(@PathVariable String orderId) {
        orderService.cancelOrder(orderId);
        return "订单取消消息已发送";
    }

    @PutMapping("/order")
    public String updateOrder(@RequestBody Order order) {
        orderService.updateOrder(order);
        return "订单更新消息已发送";
    }

    // 用户相关接口
    @PostMapping("/user")
    public String registerUser(@RequestBody User user) {
        userService.registerUser(user);
        return "用户注册消息已发送";
    }

    @PostMapping("/user/login")
    public String loginUser(@RequestParam String username) {
        userService.loginUser(username);
        return "用户登录消息已发送";
    }

    @PutMapping("/user")
    public String updateUser(@RequestBody User user) {
        userService.updateUser(user);
        return "用户更新消息已发送";
    }

    // 商品相关接口
    @PostMapping("/product")
    public String createProduct(@RequestBody Product product) {
        productService.createProduct(product);
        return "商品创建消息已发送";
    }

    @DeleteMapping("/product/{productId}")
    public String deleteProduct(@PathVariable String productId) {
        productService.deleteProduct(productId);
        return "商品删除消息已发送";
    }

    @PutMapping("/product")
    public String updateProduct(@RequestBody Product product) {
        productService.updateProduct(product);
        return "商品更新消息已发送";
    }
}
